#pragma once
#include "Observer.h"
#include <list>

using namespace std;
class Subject
{
public:
	virtual ~Subject();

	virtual void Attach(Observer* o);
	virtual void Detach(Observer* o);
	virtual void Notify();

protected:
	Subject();
private:
	list<Observer*>* observers_ = nullptr;
};

Subject::Subject()
	:observers_(new list<Observer*>())
{

}

Subject::~Subject()
{
	if (observers_)
		delete observers_;
}

void Subject::Attach(Observer* o)
{
	observers_->push_back(o);
}

void Subject::Detach(Observer* o)
{
	observers_->remove(o);
}

void Subject::Notify()
{
	for (auto i = observers_->begin(); i != observers_->end(); i++) {
		(*i)->Update(this);
	}
}

